package com.zzj.security.jwt.controller;

import com.zzj.security.jwt.entity.dto.HttpResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.security.RolesAllowed;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @ClassName SysUserInfoController
 * @Description TODO
 * @Author zhijun zeng at 23:51 2020/5/17
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "/ajax/sysUser")
public class SysUserInfoController {

    @RequestMapping(value = "/authRoles")
    @PreAuthorize(value = "hasAuthority('dbadmin')")
    public HttpResult findAuthenticatedRoles(Authentication authentication) {
        Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
        List<String> rolestr = new ArrayList<>();
        authorities.forEach((auth) -> {
            rolestr.add(auth.getAuthority());

        });
        return HttpResult.success().add(rolestr);
    }





}
